<?php

require_once 'DaoFactoryCreateQuery.php';
require_once APP_ENTITY.DS.'EntityUser.php';
require_once APP_ENTITY.DS.'ValueEntity.php';

class DaoUser {

 function __construct() {

 }
/*
 private function getElFromArray($el) {

     $user = new User();

     $user->setAttivo($el['attivo']);
     $user->setCognome($el['cognome']);
     $user->setEmail($el['email']);
     $user->setId($el['id']);
     $user->setNome($el['nome']);
     $user->setPassword($el['password']);
     $user->setUser($el['user']);

     return $user;

 }*/

 public function userList() {
        $list = array();

        $entity = new User();
        $dao = new DaoFactory();
        $sqlCreate = new DaoFactoryCreateQuery();
        $sql = $sqlCreate->genericSelect($entity, "user");
        $rs = $dao->eseguiQuery($sql);
        
        foreach ( $rs as $row) {
            $user = new User();
            $value = new ValueEntity($user, $row);
            $user = $value->getEntytyValorized();
            array_push($list, $user);

        }
        
        return $list;
 }

 function getUserByUsername($username) {

      $list = Array();
        $entity = new User();
        $entity->setUser($username);
        $dao = new DaoFactory();
        $sqlCreate = new DaoFactoryCreateQuery();
        $sql = $sqlCreate->genericSelect($entity, "user");
        $rs = $dao->eseguiQuery($sql);

        foreach ( $rs as $row) {
            $user = new User();
            $value = new ValueEntity($user, $row);
            $user = $value->getEntityValorized();
            if(!empty($user))
                array_push($list, $user);

        }
        if(empty($list))
            $entity = null;
        else
            $entity = $list[0];

        return $entity;
 }

}

 /*
 $user = new DaoUser();
 var_dump($user->getUserByUsername("admin"));
  */

?>